class LiquidTemplateFormat < ActiveModel::Validator
  def validate(record)
    record.errors[:base] << @syntax_error unless syntax_check(record)
  end

  private
  def syntax_check(record)
    begin
      Liquid::Template.parse record.template
      return true
    rescue Liquid::SyntaxError => error
      @syntax_error = error.message
      return false
    end
  end
end
